import Vue from 'vue'
import VueRouter from 'vue-router'
import login from '@/components/login'
import homePage from '@/components/homePage'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: '',
    component: login,
    hidden: true,
    meta: {
      requireAuth: true
    }
  },
  {
    path: '/login',
    name: '登录',
    component: login,
    hidden: true,
    meta: {
      requireAuth: false
    }
  },
  {
    path: '/',
    name: '首页',
    component: homePage,
    // hidden: true,
    // meta: {
    //   requireAuth: true
    // },
    children: [
      {
        path: "/config/addGoodsPage",
        meta: {
          requireAuth: true
        },
        component: () => import('@/components/functionPart/addGoodsPart/addGoodsPage'),
      },
      {
        path: "/config/configurePage",
        meta: {
          requireAuth: true
        },
        component: () => import('@/components/functionPart/configurePart/configurePage'),
      },
      {
        path: "/config/integralPage",
        meta: {
          requireAuth: true
        },
        component: () => import('@/components/functionPart/integralPart/integralPage'),
      },
      {
        path: "/config/exportPage",
        meta: {
          requireAuth: true
        },
        component: () => import('@/components/functionPart/exportPart/exportPage'),
      },
      {
        path: "/config/groupPage",
        meta: {
          requireAuth: true
        },
        component: () => import('@/components/functionPart/groupPart/groupPage'),
      },
      {
        path: "/config/luckDrawPage",
        meta: {
          requireAuth: true
        },
        component: () => import('@/components/functionPart/luckDrawPart/luckDrawPage'),
      },
      {
        path: "/config/luckPrizePage",
        meta: {
          requireAuth: true
        },
        component: () => import('@/components/functionPart/luckPrizePart/luckPrizePage'),
      }
    ],
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
router.beforeEach((to,from,next)=>{
  if(to.path === '/login')
  return next();
  //获取token
  const tokenStr = sessionStorage.getItem('authorization');
  if(!tokenStr)
  return next('/login');
  next();
  })

export default router